/**
 * Created by Administrator on 2019-7-15.
 */
$(document).ready(function () {
    new Vue({
        el: '.globalstyle',
        data: {
            inforData:[],
            main_img:"",
            main_title:"",
            tab1:true,
            tab2:false,
            tab3:false,
            tab4:false,
            tab5:false,
            page_num:1,
            current_tab:1,
            one:"市场导购",
            two:"动态资讯",
            three:"联系我们",
            three_box_txt_show:true

        },
        mounted: function(){
            var self = this;
            self.getAllInfor();

            if(localStorage.getItem("language")=="cn") {
                self.one = "市场导购";
                self.two = "动态资讯";
                self.three = "联系我们";
                self.three_box_txt_show = true;
            }else{
                self.one = "Market&nbsp;Shopping Guide";
                self.two = "Dynamic Information";
                self.three = "Contact Us";
                self.three_box_txt_show = false;
            }

            $(window).scroll(function () {
                var scrollTop = $(this).scrollTop();
                var scrollHeight = $(document).height();
                var windowHeight = $(this).height();

                if (Math.round(scrollTop + windowHeight) == scrollHeight) {
                    self.page_num += 6;
                    if( self.tab1){
                        self.getAllInfor();
                    }else{
                        $.ajax({
                            type:"GET",
                            url:"/infor/getTypeInfor",
                            data: {
                                type_id:self.current_tab,
                                language:"cn",
                                page:self.page_num
                            },
                            dataType:"json",
                            success:function(data){
                                self.inforData = data;
                                self.main_img = data[0].thumb;
                                self.main_title = data[0].title;
                            }
                        });
                    }
                    console.log("到底了,发起请求")
                }
            });
        },
        methods: {
            getAllInfor:function () {
                var self = this;
                $.ajax({
                    type:"post",
                    url:"/infor/getAllInfor",
                    data: {
                        language:"cn",
                        page:self.page_num
                    },
                    dataType:"json",
                    success:function(res){
                        if(self.page_num>1){
                            self.inforData =self.inforData.concat(res);
                        }else{
                            self.inforData = res;
                            self.main_img = res[0].thumb;
                            self.main_title = res[0].title;
                        }

                    }
                });
            },

            changeTab:function (a) {
                var self = this;
                self.current_tab = a;
                self.page_num = 1;
                switch (a){
                    case 0:
                        self.tab1 = true;
                        self.tab2 = false;
                        self.tab3 = false;
                        self.tab4 = false;
                        self.tab5 = false;
                        break;
                    case 1:
                        self.tab1 = false;
                        self.tab2 = true;
                        self.tab3 = false;
                        self.tab4 = false;
                        self.tab5 = false;
                        break;
                    case 2:
                        self.tab1 = false;
                        self.tab2 = false;
                        self.tab3 = true;
                        self.tab4 = false;
                        self.tab5 = false;
                        break;
                    case 3:
                        self.tab1 = false;
                        self.tab2 = false;
                        self.tab3 = false;
                        self.tab4 = true;
                        self.tab5 = false;
                        break;
                    case 4:
                        self.tab1 = false;
                        self.tab2 = false;
                        self.tab3 = false;
                        self.tab4 = false;
                        self.tab5 = true;
                        break;
                }

                if(a == 0){
                    self.getAllInfor();
                }else{
                    $.ajax({
                        type:"GET",
                        url:"/infor/getTypeInfor",
                        data: {
                            type_id:a,
                            language:"cn",
                            page:self.page_num
                        },
                        dataType:"json",
                        success:function(data){
                            self.inforData = data;
                            self.main_img = data[0].thumb;
                            self.main_title = data[0].title;
                        }
                    });
                }


            },

            getInforDetail:function (id) {
                window.location.href = "/page/redirectInforDetail?id="+id;
            }
        }
    });
})
